package com.ruoyi.jzzgl.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import com.ruoyi.common.web.core.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.mybatis.core.page.TableDataInfo;
import com.ruoyi.jzzgl.domain.bo.JzzglZdglBo;
import com.ruoyi.jzzgl.domain.vo.JzzglZdglVo;
import com.ruoyi.jzzgl.service.JzzglZdglService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.mybatis.core.page.PageQuery;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;

import java.util.List;

@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/jzzgl/station")
public class ZdglController extends BaseController {

    private final JzzglZdglService zdglService;

    /**
     * 分页查询站点列表
     */
    @SaCheckPermission("jzzgl:zdgl:list")
    @GetMapping("/list")
    public TableDataInfo<JzzglZdglVo> list(JzzglZdglBo bo, PageQuery pageQuery) {
        return zdglService.queryPageList(bo, pageQuery);
    }

    /**
     * 新增站点
     */
    @SaCheckPermission("jzzgl:zdgl:add")
    @PostMapping
    public R<Void> add(@Validated(AddGroup.class) @RequestBody JzzglZdglBo bo) {
        zdglService.insertByBo(bo);
        return R.ok();
    }

    /**
     * 修改站点
     */
    @SaCheckPermission("jzzgl:zdgl:edit")
    @PutMapping
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody JzzglZdglBo bo) {
        zdglService.updateByBo(bo);
        return R.ok();
    }

    /**
     * 删除站点
     */
    @SaCheckPermission("jzzgl:zdgl:remove")
    @DeleteMapping("/{ids}")
    public R<Void> remove(@PathVariable Long[] ids) {
        zdglService.deleteByIds(ids);
        return R.ok();
    }

    /**
     * 获取站点下拉列表
     */
    @SaIgnore
    @GetMapping("/selectList")
    public R<List<JzzglZdglVo>> selectList(JzzglZdglBo bo) {
        return R.ok(zdglService.selectList(bo));
    }
}
